package org.taobao.ibatiside.ui.action;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.taobao.ibatiside.core.IbatisConstant;
import org.taobao.ibatiside.core.filemodel.IbatisProject;
import org.taobao.ibatiside.ui.wizard.NewConfigFileWizard;


public class OverviewNewConfigAction extends OverviewAction {
	public static final String ID="org.taobao.ibatiside.ui.action.iov.newconfig";
	public OverviewNewConfigAction() {
		super();
		setId(ID);
		setText("New Configuration");
	}
	@Override
	public void run() {
		IbatisProject project = (IbatisProject) getSelectObject();
		Shell shell = viewer.getControl().getShell();
		if (project.getVersion() != IbatisConstant.VERSION_TWO){
		
			MessageDialog.openError(shell, "Sorry","Only iBATIS was supported!");
			return;
		}
		NewConfigFileWizard newWizard = new NewConfigFileWizard();
		newWizard.init(PlatformUI.getWorkbench(), new StructuredSelection(project.getProject()));
		WizardDialog dialog = new WizardDialog(shell, newWizard);
		dialog.open();
	}
}
